]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
status/network: Expose WirelessDeviceItem:is-hotspot
authorFlorian Müllner <fmuellner@gnome.org>
Fri, 5 Aug 2022 10:30:12 +0000 (12:30 +0200)
committerMarge Bot <marge-bot@gnome.org>
Wed, 10 Aug 2022 16:37:15 +0000 (16:37 +0000)
Whether the device is used as a hotspot is currently only
used internally for the name and icon-name properties.

But hotspots need special treatment in the toggle as well,
so turn the method into a GObject property.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2408>

js/ui/status/network.js

index 994c35c134b3a4527deb3bf1050006e669ba2ff9..431ca5ad68a89add09d19aac6aa08443acc225f5 100644 (file)
@@ -1009,6 +1009,9 @@ class NMWirelessNetworkItem extends PopupMenu.PopupBaseMenuItem {
 
 const NMWirelessDeviceItem = GObject.registerClass({
     Properties: {
+        'is-hotspot': GObject.ParamSpec.boolean('is-hotspot', '', '',
+            GObject.ParamFlags.READABLE,
+            false),
         'single-device-mode': GObject.ParamSpec.boolean('single-device-mode', '', '',
             GObject.ParamFlags.READWRITE,
             false),
@@ -1037,6 +1040,7 @@ const NMWirelessDeviceItem = GObject.registerClass({
             'notify::active-access-point', this._activeApChanged.bind(this),
             'notify::active-connection', () => this._activeConnectionChanged(),
             'notify::available-connections', () => this._availableConnectionsChanged(),
+            'state-changed', () => this.notify('is-hotspot'),
             'access-point-added', (d, ap) => {
                 this._addAccessPoint(ap);
                 this._updateItemsVisibility();
@@ -1072,7 +1076,7 @@ const NMWirelessDeviceItem = GObject.registerClass({
             return 'network-wireless-acquiring-symbolic';
 
         case NM.ActiveConnectionState.ACTIVATED: {
-            if (this._isHotSpotMaster())
+            if (this.is_hotspot)
                 return 'network-wireless-hotspot-symbolic';
 
             if (!this._canReachInternet())
@@ -1094,7 +1098,7 @@ const NMWirelessDeviceItem = GObject.registerClass({
     }
 
     get name() {
-        if (this._isHotSpotMaster())
+        if (this.is_hotspot)
             /* Translators: %s is a network identifier */
             return _('%s Hotspot').format(this._deviceName);
 
@@ -1105,6 +1109,21 @@ const NMWirelessDeviceItem = GObject.registerClass({
         return this._deviceName;
     }
 
+    get is_hotspot() {
+        if (!this._device.active_connection)
+            return false;
+
+        const {connection} = this._device.active_connection;
+        if (!connection)
+            return false;
+
+        let ip4config = connection.get_setting_ip4_config();
+        if (!ip4config)
+            return false;
+
+        return ip4config.get_method() === NM.SETTING_IP4_CONFIG_METHOD_SHARED;
+    }
+
     _activeApChanged() {
         this._activeAccessPoint?.disconnectObject(this);
         this._activeAccessPoint = this._device.active_access_point;
@@ -1207,21 +1226,6 @@ const NMWirelessDeviceItem = GObject.registerClass({
 
         return this._client.connectivity === NM.ConnectivityState.FULL;
     }
-
-    _isHotSpotMaster() {
-        if (!this._device.active_connection)
-            return false;
-
-        let connection = this._device.active_connection.connection;
-        if (!connection)
-            return false;
-
-        let ip4config = connection.get_setting_ip4_config();
-        if (!ip4config)
-            return false;
-
-        return ip4config.get_method() === NM.SETTING_IP4_CONFIG_METHOD_SHARED;
-    }
 });
 
 const NMVpnConnectionItem = GObject.registerClass({